package com.unsanctioned.radioagregator;

import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.Vitamio;

import com.unsanctioned.radioaggregator.R;
import com.unsanctioned.radioagregator.database.DBCouncelor;
import com.unsanctioned.radioagregator.http.utils.CookieManager;
import com.unsanctioned.radioagregator.utils.AppConfig;

import android.os.AsyncTask;
import android.os.Bundle;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;

public class MainActivity extends FragmentActivity {
	private static Context context = null;
	private static MediaPlayer mediaplayer = null;
	private CookieManager cookieManager = null;
	private AppConfig appConfig = null;
	private DBCouncelor dbCouncelor = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context = this;
		cookieManager = new CookieManager(this);
		appConfig = new AppConfig(this);
		dbCouncelor = new DBCouncelor(this);
		new AsyncTask<Object, Object, Boolean>() {
			@Override
	        protected void onPreExecute() {}
	        @Override
	        protected Boolean doInBackground(Object... params) {
	            return Vitamio.initialize(context);
	        }
	        @Override
	        protected void onPostExecute(Boolean inited) {
	        	mediaplayer = new io.vov.vitamio.MediaPlayer(context, true);
	        }
	    }.execute();
	    
	    View fragmentContainer = findViewById(R.id.fragment_container);
	}
	
	@Override
	public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
		// TODO Auto-generated method stub
		return super.onCreateView(parent, name, context, attrs);
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		super.onCreateContextMenu(menu, v, menuInfo);
	}
		
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	/**
	 * Get context from MainActivity, if somewhere it's needed.
	 * @return a context.
	 */
	public static Context getMainContext() {
		return context;
	}
	/**
	 * Get prepared mediaplayer if it's prepared.
	 * @return an instance of mediaplayer or <b>null</b> instead.
	 */
	public static MediaPlayer getMediaPlayer() {
		return mediaplayer;
	}
}
